<?php

class Site_info_model extends CI_Model {
	
	public function get_all_tower_provider()
	{
		$query = $this->db->where('active',1);
		$query = $this->db->order_by('tower_provider_id','ASC');
		$query = $this->db->get('t_mtr_tower_provider');
		if ($query->num_rows()) {
			return $query->result_array();
		} else {
			return FALSE;
		}
	}

	public function get_rows_tower_provider()
	{
		$this->db->where('active', 1);
		$this->db->from('t_mtr_tower_provider');	
		return $this->db->count_all_results();
	}	

	public function get_all_site()
	{
		$query = $this->db->where('active',1);
		$query = $this->db->order_by('site_id','ASC');
		$query = $this->db->get('t_mtr_site_general');
		if ($query->num_rows()) {
			return $query->result_array();
		} else {
			return FALSE;
		}
	}

	public function get_rows_site()
	{
		$this->db->where('active', 1);
		$this->db->from('t_mtr_site_general');	
		return $this->db->count_all_results();
	}	

	public function get_general_info_by_id($site_id)
	{
		$this->db->where('site_id', $site_id);
		
		$query = $this->db->get('t_mtr_site_general');
		
		return $query->row_array();
	}
	
	public function get_site_keepers_by_id($site_id)
	{
		$this->db->where('site_id', $site_id);
		
		$query = $this->db->get('t_mtr_site_l_keepers');
		
		return $query->row_array();
	}
	
	public function get_site_type()
	{
		$this->db->order_by('nama', 'ASC');
		$this->db->where('status', 1);
		
		$query = $this->db->get('t_mtr_site_type');
		
		return $query->result_array();
	}
	
	public function get_site_profile()
	{
		$this->db->order_by('descr', 'ASC');
		$this->db->where('status', 1);
		
		$query = $this->db->get('t_mtr_site_profile');
		
		return $query->result_array();
	}
	
	public function get_site_specification()
	{
		$this->db->order_by('descr', 'ASC');
		$this->db->where('status', 1);
		
		$query = $this->db->get('t_mtr_site_specification');
		
		return $query->result_array();
	}
	
	public function check_old_site_id($old_site_id)
	{
		$this->db->where('old_site_id', $old_site_id);
		
		$query = $this->db->get('t_mtr_site_general');
		
		if ($query->num_rows()) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	public function check_site_keepers($site_id)
	{
		$this->db->where('site_id', $site_id);
		
		$query = $this->db->get('t_mtr_site_l_keepers');
		
		if ($query->num_rows()) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	public function get_propinsi()
	{
		$this->db->where('status', 1);
		$this->db->order_by('descr', 'ASC');
		
		$query = $this->db->get('t_mtr_propinsi');
		
		return $query->result_array();
	}
	
	public function get_kabupaten($propinsi_id = '')
	{
		$this->db->where('propinsi_id', $propinsi_id);
		$this->db->where('status', 1);
		$this->db->order_by('descr', 'ASC');
		
		$query = $this->db->get('t_mtr_kabupaten');
		
		return $query->result_array();
	}
	
	public function get_kecamatan($kabupaten_id = '')
	{
		$this->db->where('kabupaten_id', $kabupaten_id);
		$this->db->where('status', 1);
		$this->db->order_by('descr', 'ASC');
		
		$query = $this->db->get('t_mtr_kecamatan');
		
		return $query->result_array();
	}
	
	public function get_tower_provider()
	{
		$this->db->where('active', 1);
		
		$query = $this->db->get('t_mtr_tower_provider');
		
		return $query->result_array();
	}
	
	public function get_cme_partner($key)
	{
		$this->db->like('nama', $key);
		$this->db->where('status', 1);
		$this->db->limit(20);
		
		$query = $this->db->get('t_mtr_cme_partner');
		
		return $query->result_array();
	}
	
	public function get_tenant($key)
	{
		$this->db->like('UPPER(tenant_name)', strtoupper($key));
		$this->db->where('status', 1);
		$this->db->limit(20);
		
		$query = $this->db->get('t_mtr_tenant');
		
		return $query->result_array();
	}
	
	public function get_privilege_actions($menu_id, $user_group_id)
	{
		$this->db->select('
			COALESCE (menu_add, 0) AS menu_add,
			COALESCE (menu_view, 0) AS menu_view,
			COALESCE (menu_edit, 0) AS menu_edit,
			COALESCE (menu_delete, 0) AS menu_delete,
			COALESCE (menu_approve, 0) AS menu_approve,
			COALESCE (menu_reject, 0) AS menu_reject'
			, FALSE
		);
		$this->db->where('user_group_id', $user_group_id);
		$this->db->where('menu_id', $menu_id);
		
		$query = $this->db->get('t_mtr_user_role');
		
		return $query->row_array();
	}
	
}